import { ErrorMessageMode } from '#/axios';
import { escloudHttp } from '@/utils/http/axios';

enum Api {
  uploadApi = '/eslogis-tps/userFiles/upload',
  renameFileApi = '/eslogis-tps/userFiles/rename/',
  delFileApi = '/eslogis-tps/userFiles/deleteById/',
  getDeliveryReceiptDetail = '/eslogis-tps/shippingOrder/details/',
  getDeliveryDetails = '/eslogis-tps/shippingOrder/detail/deliveryDetails/',
  shippingOrderOutBoundApi = '/eslogis-tps/shippingOrderFlow/outBound',
  shippingOrderSignFlowApi = '/eslogis-tps/shippingOrderFlow/signFlow',
  getFileListApi = '/eslogis-tps/userFiles/list',
}

/**
 * @description: 删除
 */
export function delH5FileApi(id) {
  return escloudHttp.delete<any>(
    {
      url: Api.delFileApi + id,
    },
    { errorMessageMode: 'message' },
  );
}
/**
 * 获取回单详情
 * @param Object data
 */
export function getDeliveryReceiptDetailH5(data: any, mode: ErrorMessageMode = 'message') {
  return escloudHttp.get<any>(
    {
      url: Api.getDeliveryReceiptDetail + data.id,
      data: { isH5: true },
    },
    {
      errorMessageMode: mode,
    },
  );
}

/**
 * 查询发货单/退货单详情货物明细
 * @param Object data
 */
export function getDeliveryDetailsH5(data: any, mode: ErrorMessageMode = 'message') {
  return escloudHttp.get<any>(
    {
      url: Api.getDeliveryDetails + data.id,
      data: { isH5: true },
    },
    {
      errorMessageMode: mode,
    },
  );
}

/**
 * 出库
 * @param Object data
 */
export function shippingOrderOutBound(data: any, mode: ErrorMessageMode = 'message') {
  return escloudHttp.post<any>(
    {
      url: Api.shippingOrderOutBoundApi,
      data: data,
    },
    {
      errorMessageMode: mode,
    },
  );
}

/**
 * 出库
 * @param Object data
 */
export function shippingOrderSignFlow(data: any, mode: ErrorMessageMode = 'message') {
  return escloudHttp.post<any>(
    {
      url: Api.shippingOrderSignFlowApi,
      data: data,
    },
    {
      errorMessageMode: mode,
    },
  );
}

/**
 * @description: 获取文件列表
 */
export function getUserFilesH5({ batchId, ...other }) {
  console.log('getUserFiles', other);
  return escloudHttp.get<any>(
    {
      url: `${Api.getFileListApi}/${batchId}`,
      params: other,
    },
    {
      errorMessageMode: 'none',
    },
  );
}
